import java.util.Arrays;
import java.util.Scanner;

public class dome {
    public static void main(String[] args) {
        personArr[] pre = new personArr[0];//存类数组
        PrrWay PW = new PrrWay();     //方法类
        Scanner input = new Scanner(System.in);
        char ch;
        do {
            System.out.println("\n————————————————————电话本管理系统————————————————————");
            System.out.println("1.添加    2.删除    3.修改    4.查询所有  5.根据姓名查询    0.退出");
            System.out.println("————————————————————电话本管理系统————————————————————");
            System.out.print("请选择操作：");
            int handle = input.nextInt();
            personArr p = new personArr();//存键盘输入的数据
            switch (handle) {
                //1.添加
                case 1 -> {
                    pre = Arrays.copyOf(pre, pre.length + 1);
                    System.out.print("姓名：");
                    p.name = input.next();
                    System.out.print("性别：");
                    p.sex = input.next().charAt(0);
                    System.out.print("年龄：");
                    p.age = input.nextInt();
                    System.out.print("手机号：");
                    p.phoneName = input.next();
                    System.out.print("QQ号：");
                    p.qqName = input.next();
                    System.out.print("地址：");
                    p.site = input.next();
                    // pre.personArr(name,sex,age,phoneName,qqname,site);
                    pre[pre.length - 1] = p;
                    pre[pre.length - 1].get();
                }
                // 2.删除
                case 2 -> {
                    System.out.print("请输入要删除的用户名字：");
                    String name = input.next();
                    System.out.println(PW.del(pre, name));
                }

                //3.修改
                case 3 -> {
                    System.out.print("请输入要修改的用户名字：");
                    String name = input.next();
                    int alter = PW.alter(pre, name);
                    if ((-1) != alter) {
                        System.out.print("姓名：");
                        p.name = input.next();
                        System.out.print("性别：");
                        p.sex = input.next().charAt(0);
                        System.out.print("年龄：");
                        p.age = input.nextInt();
                        System.out.print("手机号：");
                        p.phoneName = input.next();
                        System.out.print("QQ号：");
                        p.qqName = input.next();
                        System.out.print("地址：");
                        p.site = input.next();
                        pre[alter] = p;
                        System.out.println("修改成功");
                    } else {
                        System.out.println("查询不您所输入的信息！");
                    }

                }
                //4.查询所有
                case 4 -> {
                    PW.traversal(pre);
                }
                //5.根据姓名查询
                case 5 -> {
                    PW.traversal(pre);
                }
                case 0 -> {
                    break;
                }
            }
        } while (true);
    }

}
